
package com.example.backweb.service.impl;
import com.example.backweb.mapper.AdminMapper;
import com.example.backweb.pojo.Teacher;
import com.example.backweb.pojo.Teacherinfo;
import com.example.backweb.pojo.tti;
import com.example.backweb.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xu
 * @since 2023-11-24
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Teacher> implements IAdminService {

    @Autowired
    AdminMapper adminMapper;
    @Autowired
    TeacherServiceImpl teacherService;
    @Autowired
    public boolean delete(Teacher teacher) {
        if("admin".equals(teacher.getTea_id())) return false;
        return adminMapper.deleteUser(teacher.getTea_id())&& adminMapper.deleteUserinfo(teacher.getTea_id());
    }

    @Override
    public List<Teacher> selectall() {
        return adminMapper.selectall();
    }

    @Override
    public Teacherinfo selectone(String tea_id) {
        return adminMapper.selectone(tea_id);
    }

    @Override
    public List<Teacher> selectteacher(String id) {
        return adminMapper.selectteacher(id);
    }

    @Override
    public boolean update(tti t) {
        Teacher teacher=t.getTeacher();
        if(teacher.getTea_id()==null&&teacher.getPassword()==null&&teacher.getLast_idcard()==null) {
            return adminMapper.updateuserinfo(t.getInfo());
        }
        else if(teacher.getTea_id()==null)
        {
            teacher.setTea_id(t.getInfo().getTea_id());
        }
        String pwd=teacher.getPassword();
        String ls=teacher.getLast_idcard();
        if(pwd==null) pwd=ls;
        if(ls!=null)
        {
        }
        if(pwd!=null)
        {
        }
        Teacherinfo info=t.getInfo();
        if(info==null) return adminMapper.updateuser(teacher);
        return adminMapper.updateuser(teacher)&&adminMapper.updateuserinfo(info);
    }

    @Override
    public Boolean selectrole(String tea_id) {
        return adminMapper.selectrole(tea_id);
    }
}
